package com.kb.erp.entity.quote;
import com.alibaba.excel.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Response {
    private int code;
    private String msg;
    private int count;
    private List<Item> data;

    public void adjustPricesForInflation() {
        if (data != null) {
            for (Item product : data) {
                if (product.getMyPricing() != null) {
                    for (Item.Pricing price : product.getMyPricing()) {
                        // Adjust the cost
                        BigDecimal tem=new BigDecimal(price.getPrice()).multiply(BigDecimal.valueOf(1.13));
                        price.setPrice(tem.toString());
                    }
                }


                if (product.getStandardPricing() != null) {
                    for (Item.Pricing price : product.getStandardPricing()) {
                        // Adjust the cost
                        BigDecimal tem=new BigDecimal(price.getPrice()).multiply(BigDecimal.valueOf(1.13));
                        price.setPrice(tem.toString());
                    }
                }
            }


        }


    }


    // Getters and Setters
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }
    public String getMsg() { return msg; }
    public void setMsg(String msg) { this.msg = msg; }
    public int getCount() { return count; }
    public void setCount(int count) { this.count = count; }
    public List<Item> getData() { return data; }
    public void setData(List<Item> data) { this.data = data; }
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Item {
        private String ven_partnumber;
        private String ven_mfc_mode;
        private String ven_brand;


        private List<MouseAttribute> ven_package;

        public List<MouseAttribute> getVen_package() {
            return ven_package;
        }

        public void setVen_package(List<MouseAttribute> ven_package) {
            this.ven_package = ven_package;
        }

        //乘以1.13

        @JsonIgnoreProperties(ignoreUnknown = true)
        @Data
        public static class MouseAttribute{
            @JsonProperty("AttributeName")
            private String AttributeName;
            @JsonProperty("AttributeValue")
            private String AttributeValue;
        }


        public String getVen_desc_dtl() {
            return ven_desc_dtl;
        }

        public void setVen_desc_dtl(String ven_desc_dtl) {
            this.ven_desc_dtl = ven_desc_dtl;
        }

        private String ven_desc_dtl;

        @JsonProperty("QuantityAvailable")
        private String QuantityAvailable;

        public String getMinimumOrderQuantity() {
            return MinimumOrderQuantity;
        }

        public void setMinimumOrderQuantity(String minimumOrderQuantity) {
            MinimumOrderQuantity = minimumOrderQuantity;
        }

        @JsonProperty("MinimumOrderQuantity")
        private String MinimumOrderQuantity;

        @JsonProperty("MyPricing")
        //折扣价
        private List<Pricing> MyPricing;
        //标准价
        @JsonProperty("StandardPricing")
        private List<Pricing> StandardPricing;


        @JsonProperty("ProductCompliance")
        private List<Compliance> ProductCompliance;

        public List<Compliance> getProductCompliance() {
            return ProductCompliance;
        }

        public void setProductCompliance(List<Compliance> productCompliance) {
            ProductCompliance = productCompliance;
        }

        // Getters and Setters
        public String getVen_partnumber() { return ven_partnumber; }
        public void setVen_partnumber(String ven_partnumber) { this.ven_partnumber = ven_partnumber; }
        public String getVen_mfc_mode() { return ven_mfc_mode; }
        public void setVen_mfc_mode(String ven_mfc_mode) { this.ven_mfc_mode = ven_mfc_mode; }

        public String getVen_brand() { return ven_brand; }
        public void setVen_brand(String ven_brand) { this.ven_brand = ven_brand; }


        public String getQuantityAvailable() { return QuantityAvailable; }
        public void setQuantityAvailable(String quantityAvailable) { this.QuantityAvailable = quantityAvailable; }

        public List<Pricing> getMyPricing() { return MyPricing; }
        public void setMyPricing(List<Pricing> myPricing) { this.MyPricing = myPricing; }
        public List<Pricing> getStandardPricing() { return StandardPricing; }
        public void setStandardPricing(List<Pricing> standardPricing) { this.StandardPricing = standardPricing; }




        @Data
        public static class Compliance{
            @JsonProperty("ComplianceName")
            private String ComplianceName;
            @JsonProperty("ComplianceValue")
            private String ComplianceValue;
        }


        public static class Pricing {
            @JsonProperty("Quantity")
            private int Quantity;
            @JsonProperty("Price")
            private String Price;
            @JsonProperty("Currency")
            private String Currency;

            // Getters and Setters
            public int getQuantity() { return Quantity; }
            public void setQuantity(int quantity) { this.Quantity = quantity; }
            public String getPrice() { return Price; }
            public void setPrice(String price) { this.Price = price; }
            public String getCurrency() { return Currency; }
            public void setCurrency(String currency) { this.Currency = currency; }
        }

        public void sortPricingLists() {
            if (MyPricing != null) {
                MyPricing.sort(Comparator.comparingInt(Pricing::getQuantity));
            }
            if (StandardPricing != null) {
                StandardPricing.sort(Comparator.comparingInt(Pricing::getQuantity));
            }
        }


        //标准价
        public String generatePriceString2() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;

            // Handling MyPricing
            if (MyPricing != null && !MyPricing.isEmpty()) {
                for (Pricing myPrice : MyPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }

                    String standardPrice = findStandardPrice(myPrice.getQuantity());
                    sb.append(standardPrice);


                    isFirst = false;
                }
            }

            return sb.toString();
        }
        //数量
        public String generatePriceString3() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;

            // Handling MyPricing
            if (MyPricing != null && !MyPricing.isEmpty()) {
                for (Pricing myPrice : MyPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }
                    sb.append(myPrice.getQuantity());


                    isFirst = false;
                }
            }

            return sb.toString();
        }




        //折扣价
        public String generatePriceString() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;

            // Handling MyPricing
            if (MyPricing != null && !MyPricing.isEmpty()) {
                for (Pricing myPrice : MyPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }

                           sb .append(myPrice.getPrice());


                    isFirst = false;
                }
            }

            return sb.toString();
        }

        private String findStandardPrice(int quantity) {
            if (StandardPricing != null) {
                for (Pricing standardPrice : StandardPricing) {
                    if (standardPrice.getQuantity() == quantity) {
                        return standardPrice.getPrice();
                    }
                }
            }
            return ""; // Return empty string if no matching price found
        }


    }



}
